There are two types of operators, namely, unary and binary operators. For examples,
+ in the expression 1 + 2.' in the matrix transpose expression A'.> in the expression a > b.A unary operator requires just one operand. The following shows unary operators supported in the app.
| Operator | Operation | Examples |
|---|---|---|
+ | Unary plus | +2, -[1 2; 3 4] |
- | Unary minus | -1, -[1 2; 3 4] |
' | Conjugate transpose | ones(2,3)' |
.' | Transpose | ones(2,3).' |
!, ~ | Logical NOT | ~true, !(1 > 4) |
Unary operators are operated in element-wise manner. That means, it is applied to each of the elements in an array individually.
A majority of operators in this app are binary. It has two operands, for examples,
+ in 1 + 2== in ones(3,4) == zeros(3,4)>= in 3 >= 1The operands should have compatible sizes as explained below. Otherwise, the operation cannot be performed.
A binary operator may perform an element-wise operation or a matrix operation. When an element-wise operation is performed, the two operands must have compatible sizes. In the following example, two arrays of compatible sizes are added using the addition operator.
A = ones(2,3,4);
B = rand(2,3,4);
C = A + B
In the above example, two arrays A and B are added to give C. The addition is performed in an element-wise fashion. That is, each element of A is added to the element of B at the same position, i.e., A(i) + B(i) for all i. It is usually expected that size(A, i) and size(B, i) are the same for all i, so that the size of the result, size(C, i), can be inferred. However, if size(A, i) and size(B, i) are different, size(C, i) can still be inferred when either size(A, i) == 1 or size(B, i) == 1 holds. In this situation, the dimension of unit length is expanded to match the length of the other array.
The arrays A and B have compatible sizes if at least one of the following is satisfied for all i equal to 1, 2, ..., max(ndim(A), ndim(B)).
size(A, i) == size(B, i)size(A, i) == 1size(B, i) == 1Otherwise, A and B are said to have incompatible sizes.
1 + rand(3,4)
ans =
1.2533 1.1439 1.3350 1.3325
1.6077 1.2538 1.0825 1.6245
1.1383 1.2089 1.7501 1.9005
ones(3,1) + rand(3,4)
ans =
1.4848 1.0346 1.3401 1.2939
1.2790 1.9602 1.2750 1.1826
1.9858 1.4399 1.9184 1.1713
ones(2,3) + rand(2,3,4)
ans(:, :, 1) =
1.3650 1.9548 1.1026
1.2504 1.1537 1.8637
ans(:, :, 2) =
1.6086 1.3317 1.6006
1.9093 1.3834 1.1635
ans(:, :, 3) =
1.9176 1.5907 1.3863
1.0363 1.6654 1.2127
ans(:, :, 4) =
1.2852 1.8740 1.8748
1.1846 1.9509 1.0385
Some operators by default perform matrix operations when both of the operands are matrices having the correct sizes. For example, [1 2] * [1 2; 3 4] performs matrix multiplication that gives the array [7, 10].
The following is a list of all matrix operations supported by SIMO. Each of the operations performs the following size check:
| Matrix Operation | Operator |
|---|---|
| Power | ^ |
| Solving matrix equation | \ |
| Multiplication | * |
| Solving the matrix equation | / |
| Conjugate transpose | ' |
| Non-conjugate transpose | .' |